package org.web.standardplatform.client.domain.check;

import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface TableSqlCheckConstant {

    enum STATUS {
        ON, OFF
    }

    enum PARAM_TYPE {
        TABLE, COLUMN
    }



    /**
     * 用来定义校验的参数内容。
     */
    @Getter
    public enum PARAM_ENUM {

        TABLE_NAME(PARAM_TYPE.TABLE, "TableName", "表名"),
        TABLE_PRIMARY_KEY_LIST(PARAM_TYPE.TABLE, "PrimaryKeyList", "主键"),
        TABLE_FOREIGN_KEY_LIST(PARAM_TYPE.TABLE, "ForeignKeyList", "外键名称"),
        TABLE_FOREIGN_COLUMN_LIST(PARAM_TYPE.TABLE, "ForeignColumnList", "外键列名"),
        TABLE_INDEX_NAME_LIST(PARAM_TYPE.TABLE, "IndexNameList", "表索引名称"),
        TABLE_INDEX_COLUMN_NAME_LIST(PARAM_TYPE.TABLE, "IndexColumnNameList", "表索引列名称"),
        TABLE_COMMENTS(PARAM_TYPE.TABLE, "TableComment", "表的描述"),
        TABLE_COLUMN_NAME_LIST(PARAM_TYPE.TABLE, "ColumnNameList", "表的描述"),
        TABLE_LOGIC_UNIQUE_COLUMN_LIST(PARAM_TYPE.TABLE, "LogicUniqueColumnList", "主键"),
        TABLE_LOGIC_REDUNDANCY_COLUMN_LIST(PARAM_TYPE.TABLE, "RedundancyColumnList", "主键"),
        COLUMN_NAME(PARAM_TYPE.COLUMN, "ColumnName", "列名"),
        COLUMN_COMMENT(PARAM_TYPE.COLUMN, "ColumnComment", "列的描述"),
        COLUMN_TYPE(PARAM_TYPE.COLUMN, "ColumnType", "列的类型"),
        COLUMN_ALLOW_NULL(PARAM_TYPE.COLUMN, "AllowNull", "有键的列名");

        private final PARAM_TYPE paramType;
        private final String paramName;
        private final String comments;

        PARAM_ENUM(PARAM_TYPE paramType, String paramName, String comments) {
            this.comments = comments;
            this.paramType = paramType;
            this.paramName = paramName;
        }

        public static final Map<String, Map<String, PARAM_ENUM>> PARAM_ENUM_MAP = new HashMap<>();
        public static final List<String> TABLE_PARAM_NAME_LIST = new ArrayList<>();
        public static final List<String> COLUMN_PARAM_NAME_LIST = new ArrayList<>();

        static {
            for (PARAM_ENUM paramEnum : PARAM_ENUM.values()) {
                PARAM_ENUM_MAP.computeIfAbsent(paramEnum.getParamType().name(), k -> new HashMap<>());
                PARAM_ENUM_MAP.get(paramEnum.getParamType().name()).put(paramEnum.getParamName(), paramEnum);
                if (paramEnum.getParamType() == PARAM_TYPE.TABLE) {
                    TABLE_PARAM_NAME_LIST.add(paramEnum.getParamName());
                } else if (paramEnum.getParamType() == PARAM_TYPE.COLUMN) {
                    COLUMN_PARAM_NAME_LIST.add(paramEnum.getParamName());
                }
            }
        }

    }

    enum FUNCTION_TYPE {
        NotNull,
        Pattern,
        Include,
        NotInclude
    }


    enum LEVEL {
        PROHIBIT, WARN, INFO
    }
}
